<?php
namespace app\super\controller;
use think\Db;
use think\Controller;
use  think\Request;

class Menu extends Base
{
    
	public function Index(){
		
		
		
		
		
		 return view();
	}
	
	
	
	function Add(){
		
		$request = Request::instance();
	
		
		if($request->isPost()){
				$data["id"] =$request->post('id');
				$data["textstr"] =$request->post('textstr');
				$data["imgurlsrc"] =$request->post('imgurlsrc');
				$data["valuestr"] =$request->post('valuestr');
				$data["nvaurl"] =$request->post('nvaurl');
				$data["parentid"] =$request->post('parentid');
				$data["seq"] =$request->post('seq');
				
			if($data["id"]){
				
			
				
				if(db('sys_menu')->update($data)){
					
					  return ['status'=>200,'message'=>'修改成功'];
				}else{
					 return ['status'=>500,'message'=>'修改失败'];
				}
			}else{
				
			
			  if(db('sys_menu')->insertGetId($data)){
					 return ['status'=>200,'message'=>'添加成功'];
					
				}else{
					return ['status'=>500,'message'=>'添加失败'];
				}
			}
			
		}else{
			
			if($request->get('id')){
				$info =db('sys_menu')->where("id=".$_GET["id"])->find();
				$this->assign('info',$info);
				
			}
		
			$treelist =db('sys_menu')->where("parentid=0")->select();
			$this->assign('tree',$treelist);
		
			
		}
		
		
	
	
		return view();
	}
	 public function GetMenu(){
		$where="";
		$count =db('sys_menu')->where($where)->count();
		$first = $_GET["size"] * ($_GET["page"] -1);
		 
		$list = db('sys_menu')->where("")->limit($first,$_GET["size"])->select();
		$obj["count"]=(int)($count/$_GET["size"])+1;
		$obj["allcount"]=$count;
		$obj["list"]=$list;
		return json($obj);
		
	}
	 public function GetMenuList(){
		 $request = Request::instance();
		 $parentid="0";
		 if($request->post("parentid")){
			 $parentid=$request->post("parentid");
			 
		 }
		 
		$where="parentid=".$parentid;
		$list = db('sys_menu')->where($where)->select();
	
		return json($list);
		
	}
	function Del(){
		$request = Request::instance();
		$id =$request->post('id');
		
		
		 
			$where = 'id='.$id;
		  
		   $list=db('sys_menu')->where($where)->delete();
		   if($list!==false) {
			 return ['status'=>200,'message'=>'删除成功'];
		   }else{
			  return ['status'=>500,'message'=>'删除失败'];
		   }
		
	}
}
